﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.IO;
using System.Windows.Interop;

namespace PPSignSDKDemoSharp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            comboBox_device.SelectedIndex = 0;
            comboBox_dpi.SelectedIndex = 0;
            Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
        }

        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            L398UnInitBtn.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent));
        }

        private const Int32 MAX_PATH = 260;
        private bool m_bShow = false;
        private ImportDll.CallBackMyFun1 fun = null;

        private ImportDll.NOTIFYREALTIMESIGNDATA _RealDataCallback = null;
        private bool m_bEnableSaveVideo = true;
        private IntPtr g_hMainWnd = IntPtr.Zero;

        private const Int32 L1000_SCREEN_WIDTH = 1280;
        private const Int32 L1000_SCREEN_HEIGHT = 800;
        L1000SignWnd g_L1000SignWnd = null;
        private IntPtr g_hL1000SignWnd = IntPtr.Zero;
        private Brush m_brushOriginalDrawRegionBackground;

        private void EnableBtn(bool bEnable)
        {
            if (bEnable)
            {
                L398InitBtn.IsEnabled = false;
                L398UnInitBtn.IsEnabled = true;

            }
            else
            {
                L398InitBtn.IsEnabled = true;
                L398UnInitBtn.IsEnabled = false;
                OpenLedL398Btn.IsEnabled = false;
                CloseLEDL398Btn.IsEnabled = false;
                GetCertL398Btn.IsEnabled = false;
                VersionL398Btn.IsEnabled = false;
                ReadCertL398Btn.IsEnabled = false;
                PadIDL398Btn.IsEnabled = false;
                DelFileL398Btn.IsEnabled = false;
                PenIDL398Btn.IsEnabled = false;
                ShowVerL398Btn.IsEnabled = false;
                combL398GetCert.IsEnabled = false;
                combL398ReadCert.IsEnabled = false;
                combL398DelFile.IsEnabled = false;
            }
            textL398Status.IsEnabled = bEnable;
            SaveImageL398Btn.IsEnabled = bEnable;
            GetSizeL398Btn.IsEnabled = bEnable;
            GetPointL398Btn.IsEnabled = bEnable;
            EncodeL398Btn.IsEnabled = bEnable;
            DecodeL398Btn.IsEnabled = bEnable;
            AboutL398Btn.IsEnabled = bEnable;
            GetDevInfL398Btn.IsEnabled = bEnable;
            SetClipL398Btn.IsEnabled = bEnable;

            combL398Image.Items.Clear();
            combL398Image.Items.Add("BMP");
            combL398Image.Items.Add("JPG");
            combL398Image.Items.Add("PNG");
            combL398Image.Items.Add("GIF");
            combL398Image.Items.Add("TIFF");
            combL398Image.Items.Add("PDF");
            combL398Image.Items.Add("SVG");
            combL398Image.SelectedIndex = 0;
            combL398Image.IsEnabled = bEnable;

            combL398Color.Items.Clear();
            combL398Color.Items.Add("Red");
            combL398Color.Items.Add("Green");
            combL398Color.Items.Add("Blue");
            combL398Color.Items.Add("Black");
            combL398Color.Items.Add("White");
            combL398Color.IsEnabled = bEnable;

            combL398Style.IsEnabled = bEnable;
            combL398GetPoint.IsEnabled = bEnable;
            combL398Encode.IsEnabled = bEnable;
            combL398DevInfo.IsEnabled = bEnable;
            ClearL398Btn.IsEnabled = bEnable;
            textClipX.IsEnabled = bEnable;
            textClipY.IsEnabled = bEnable;
            ColorL398lab.IsEnabled = bEnable;
            StyleL398lab.IsEnabled = bEnable;
            labelWidth.IsEnabled = bEnable;
            InputL398lab.IsEnabled = bEnable;
            textBoxfile.Text = "";
            combWidth.IsEnabled = bEnable;

            SaveVideoBtn.IsEnabled = false;
            ComboVideo.IsEnabled = false;
            comboBox_FPS.IsEnabled = false;
            EnableVideoBtn.IsEnabled = bEnable;

            if (bEnable)
                EnableVideoBtn.Content = "Enable";

            if ((m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE) ||
                (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE))
                PadIDL398Btn.IsEnabled = bEnable;

            if ((m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE) ||
                (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE) ||
                (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE))
            {
                RealTimeDataPanel.IsEnabled = bEnable;
            }

            comboBox_dpi.IsEnabled = bEnable;
            if (bEnable)
            {
                textClipX.Text = "";
                textClipY.Text = "";

                combL398DevInfo.SelectedIndex = 0;
                combL398Image.SelectedIndex = 0;
                combL398Color.SelectedIndex = 3;
                combL398Style.SelectedIndex = 0;
                combL398GetPoint.SelectedIndex = 0;
                combL398Encode.SelectedIndex = 0;
                combWidth.SelectedIndex = 2;
            }
        }
        private void EnableL398Btn(bool bEnable)
        {
            if (bEnable)
            {
                L398InitBtn.IsEnabled = false;
                L398UnInitBtn.IsEnabled = true;
            }
            else
            {
                L398InitBtn.IsEnabled = true;
                L398UnInitBtn.IsEnabled = false;
            }

            ClearL398Btn.IsEnabled = bEnable;
            SaveImageL398Btn.IsEnabled = bEnable;
            ColorL398lab.IsEnabled = bEnable;
            GetDevInfL398Btn.IsEnabled = bEnable;
            textL398Status.IsEnabled = bEnable;

            combL398Image.Items.Clear();
            combL398Image.Items.Add("BMP");
            combL398Image.Items.Add("JPG");
            combL398Image.Items.Add("PNG");
            combL398Image.Items.Add("GIF");
            combL398Image.Items.Add("TIFF");
            combL398Image.Items.Add("PDF");
            combL398Image.Items.Add("SVG");
            combL398Image.SelectedIndex = 0;
            combL398Image.IsEnabled = bEnable;

            combL398Color.Items.Clear();
            combL398Color.Items.Add("Black");
            combL398Color.Items.Add("Red");
            combL398Color.Items.Add("Green");
            combL398Color.Items.Add("Blue");
            combL398Color.Items.Add("Yellow");
            combL398Color.SelectedIndex = 0;
            combL398Color.IsEnabled = bEnable;

            labelWidth.IsEnabled = bEnable;
            OpenLedL398Btn.IsEnabled = bEnable;
            CloseLEDL398Btn.IsEnabled = bEnable;
            ShowVerL398Btn.IsEnabled = bEnable;
            PadIDL398Btn.IsEnabled = bEnable;
            EncodeL398Btn.IsEnabled = bEnable;
            StyleL398lab.IsEnabled = bEnable;
            GetCertL398Btn.IsEnabled = bEnable;
            ReadCertL398Btn.IsEnabled = bEnable;
            PenIDL398Btn.IsEnabled = bEnable;
            GetSizeL398Btn.IsEnabled = bEnable;
            combL398Encode.IsEnabled = bEnable;
            combL398Style.IsEnabled = bEnable;
            combL398GetCert.IsEnabled = bEnable;
            combL398ReadCert.IsEnabled = bEnable;
            VersionL398Btn.IsEnabled = bEnable;
            GetPointL398Btn.IsEnabled = bEnable;
            DecodeL398Btn.IsEnabled = bEnable;
            DelFileL398Btn.IsEnabled = bEnable;
            SetClipL398Btn.IsEnabled = bEnable;
            combL398GetPoint.IsEnabled = bEnable;
            combL398DelFile.IsEnabled = bEnable;
            combL398DevInfo.IsEnabled = bEnable;
            textClipX.IsEnabled = bEnable;
            textClipY.IsEnabled = bEnable;
            AboutL398Btn.IsEnabled = bEnable;
            ColorL398lab.IsEnabled = bEnable;
            StyleL398lab.IsEnabled = bEnable;
            InputL398lab.IsEnabled = bEnable;

            RealTimeDataPanel.IsEnabled = bEnable;

            SaveVideoBtn.IsEnabled = false;
            ComboVideo.IsEnabled = false;
            comboBox_FPS.IsEnabled = false;
            EnableVideoBtn.IsEnabled = bEnable;

            if (bEnable)
                EnableVideoBtn.Content = "Enable";

            comboBox_dpi.IsEnabled = bEnable;
            combWidth.IsEnabled = bEnable;

            if (bEnable)
            {
                textClipX.Text = "";
                textClipY.Text = "";

                combL398DevInfo.SelectedIndex = 0;
                combL398DelFile.SelectedIndex = 0;
                combL398GetPoint.SelectedIndex = 0;
                combL398ReadCert.SelectedIndex = 0;
                combL398GetCert.SelectedIndex = 0;
                combL398Style.SelectedIndex = 0;
                combL398Encode.SelectedIndex = 0;
                combL398Image.SelectedIndex = 0;
                combWidth.SelectedIndex = 2;

            }
            textBoxfile.Text = "";
        }

        private void EnableL501FBtn(bool bEnable)
        {
            if (bEnable)
            {
                L398InitBtn.IsEnabled = false;
                L398UnInitBtn.IsEnabled = true;
            }
            else
            {
                L398InitBtn.IsEnabled = true;
                L398UnInitBtn.IsEnabled = false;
            }

            ClearL398Btn.IsEnabled = bEnable;
            SaveImageL398Btn.IsEnabled = bEnable;
            ColorL398lab.IsEnabled = bEnable;
            GetDevInfL398Btn.IsEnabled = bEnable;
            textL398Status.IsEnabled = bEnable;

            combL398Image.Items.Clear();
            combL398Image.Items.Add("BMP");
            combL398Image.Items.Add("JPG");
            combL398Image.Items.Add("PNG");
            combL398Image.Items.Add("GIF");
            combL398Image.Items.Add("TIFF");
            combL398Image.Items.Add("PDF");
            combL398Image.Items.Add("SVG");
            combL398Image.SelectedIndex = 0;
            combL398Image.IsEnabled = bEnable;

            combL398Color.Items.Clear();
            combL398Color.Items.Add("Black");
            combL398Color.Items.Add("Red");
            combL398Color.Items.Add("Green");
            combL398Color.Items.Add("Blue");
            combL398Color.Items.Add("Yellow");
            combL398Color.SelectedIndex = 0;
            //combL398Color.IsEnabled = bEnable;

            labelWidth.IsEnabled = bEnable;
            //OpenLedL398Btn.IsEnabled = bEnable;
            //CloseLEDL398Btn.IsEnabled = bEnable;
            //ShowVerL398Btn.IsEnabled = bEnable;
            PadIDL398Btn.IsEnabled = bEnable;
            EncodeL398Btn.IsEnabled = bEnable;
            StyleL398lab.IsEnabled = bEnable;
            GetCertL398Btn.IsEnabled = bEnable;
            ReadCertL398Btn.IsEnabled = bEnable;
            PenIDL398Btn.IsEnabled = bEnable;
            GetSizeL398Btn.IsEnabled = bEnable;
            combL398Encode.IsEnabled = bEnable;
            combL398Style.IsEnabled = bEnable;
            combL398GetCert.IsEnabled = bEnable;
            combL398ReadCert.IsEnabled = bEnable;
            VersionL398Btn.IsEnabled = bEnable;
            GetPointL398Btn.IsEnabled = bEnable;
            DecodeL398Btn.IsEnabled = bEnable;
            DelFileL398Btn.IsEnabled = bEnable;
            SetClipL398Btn.IsEnabled = bEnable;
            combL398GetPoint.IsEnabled = bEnable;
            combL398DelFile.IsEnabled = bEnable;
            combL398DevInfo.IsEnabled = bEnable;
            textClipX.IsEnabled = bEnable;
            textClipY.IsEnabled = bEnable;
            AboutL398Btn.IsEnabled = bEnable;
            ColorL398lab.IsEnabled = bEnable;
            StyleL398lab.IsEnabled = bEnable;
            InputL398lab.IsEnabled = bEnable;

            RealTimeDataPanel.IsEnabled = bEnable;

            SaveVideoBtn.IsEnabled = false;
            ComboVideo.IsEnabled = false;
            comboBox_FPS.IsEnabled = false;
            EnableVideoBtn.IsEnabled = bEnable;

            if (bEnable)
                EnableVideoBtn.Content = "Enable";

            comboBox_dpi.IsEnabled = bEnable;
            combWidth.IsEnabled = bEnable;

            if (bEnable)
            {
                textClipX.Text = "";
                textClipY.Text = "";

                combL398DevInfo.SelectedIndex = 0;
                combL398DelFile.SelectedIndex = 0;
                combL398GetPoint.SelectedIndex = 0;
                combL398ReadCert.SelectedIndex = 0;
                combL398GetCert.SelectedIndex = 0;
                combL398Style.SelectedIndex = 0;
                combL398Encode.SelectedIndex = 0;
                combL398Image.SelectedIndex = 0;
                combWidth.SelectedIndex = 2;

            }
            textBoxfile.Text = "";
        }

        private void EnableL1000Btn(bool bEnable)
        {
            if (bEnable)
            {
                L398InitBtn.IsEnabled = false;
                L398UnInitBtn.IsEnabled = true;

            }
            else
            {
                L398InitBtn.IsEnabled = true;
                L398UnInitBtn.IsEnabled = false;
            }
            textL398Status.IsEnabled = bEnable;
            SaveImageL398Btn.IsEnabled = bEnable;
            GetSizeL398Btn.IsEnabled = bEnable;
            GetPointL398Btn.IsEnabled = bEnable;
            EncodeL398Btn.IsEnabled = bEnable;
            DecodeL398Btn.IsEnabled = bEnable;
            AboutL398Btn.IsEnabled = bEnable;
            GetDevInfL398Btn.IsEnabled = bEnable;
            SetClipL398Btn.IsEnabled = bEnable;
            PadIDL398Btn.IsEnabled = bEnable;

            combL398Image.Items.Clear();
            combL398Image.Items.Add("BMP");
            combL398Image.Items.Add("JPG");
            combL398Image.Items.Add("PNG");
            combL398Image.Items.Add("GIF");
            combL398Image.Items.Add("TIFF");
            combL398Image.Items.Add("PDF");
            combL398Image.Items.Add("SVG");
            combL398Image.SelectedIndex = 0;
            combL398Image.IsEnabled = bEnable;

            combL398Color.Items.Clear();
            combL398Color.Items.Add("Black");
            combL398Color.Items.Add("Red");
            combL398Color.Items.Add("Green");
            combL398Color.Items.Add("Blue");
            combL398Color.Items.Add("Yellow");
            combL398Color.SelectedIndex = 0;
            //combL398Color.IsEnabled = bEnable;

            combL398Style.IsEnabled = bEnable;
            combL398GetPoint.IsEnabled = bEnable;
            combL398Encode.IsEnabled = bEnable;
            combL398DevInfo.IsEnabled = bEnable;
            ClearL398Btn.IsEnabled = bEnable;
            textClipX.IsEnabled = bEnable;
            textClipY.IsEnabled = bEnable;
            ColorL398lab.IsEnabled = bEnable;
            StyleL398lab.IsEnabled = bEnable;
            labelWidth.IsEnabled = bEnable;
            InputL398lab.IsEnabled = bEnable;
            textBoxfile.Text = "";
            combWidth.IsEnabled = bEnable;

            SaveVideoBtn.IsEnabled = false;
            ComboVideo.IsEnabled = false;
            comboBox_FPS.IsEnabled = false;
            EnableVideoBtn.IsEnabled = bEnable;

            if (bEnable)
                EnableVideoBtn.Content = "Enable";

            comboBox_dpi.IsEnabled = bEnable;
            if (bEnable)
            {
                textClipX.Text = "";
                textClipY.Text = "";

                combL398DevInfo.SelectedIndex = 0;
                combL398Image.SelectedIndex = 0;
                combL398Style.SelectedIndex = 0;
                combL398GetPoint.SelectedIndex = 0;
                combL398Encode.SelectedIndex = 0;
                combWidth.SelectedIndex = 2;
            }
        }


        ImportDll.DEVICE_TYPE_ID m_deviceID = ImportDll.DEVICE_TYPE_ID.NONE_DEVICE;

        private void InitialNatureDevice()
        {
            IntPtr handle = ImportDll.PPNature_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, g_hMainWnd);
            if (handle.ToInt32() < 0)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            ImportDll.PPNature_SetCanvasSize(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, 0, 0, (int)DrawRegion.Width, (int)DrawRegion.Height);

            EnableBtn(true);
        }

        private void InitialL398Device()
        {
            bool result = ImportDll.PPL398_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, g_hMainWnd,0,0, (int)DrawRegion.Width, (int)DrawRegion.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            if (fun == null)
                fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);

            if (_RealDataCallback == null)
                _RealDataCallback = new ImportDll.NOTIFYREALTIMESIGNDATA(RealTimeDataCallback);

            Int32 ret = ImportDll.PPL398_SignatureStatusCallback(m_deviceID, fun);

            long retlong = ImportDll.PPL398_RealTimeSignatureDataCallback(m_deviceID, _RealDataCallback);

            EnableL398Btn(true);
        }


        private void InitialL500Device()
        {
            bool result = ImportDll.PPL500_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, g_hMainWnd, 0, 0, (int)DrawRegion.Width, (int)DrawRegion.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            if (fun == null)
                fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);
            Int32 ret = ImportDll.PPL500_SignatureStatusCallback(m_deviceID, fun);

            if (_RealDataCallback == null)
                _RealDataCallback = new ImportDll.NOTIFYREALTIMESIGNDATA(RealTimeDataCallback);

            long retlong = ImportDll.PPL500_RealTimeSignatureDataCallback(m_deviceID, _RealDataCallback);

            EnableL398Btn(true);
        }

        private void InitialL501FDevice()
        {
            bool result = ImportDll.PPL501F_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, g_hMainWnd, 0, 0, (int)DrawRegion.Width, (int)DrawRegion.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }

            int nFPImageWidth = 135;
            int nFPImageHeight = 150;
            int nDrawRegionWidth = (int)DrawRegion.Width;
            int nDrawRegionHeight = (int)DrawRegion.Height;
            int x = (nDrawRegionWidth - nFPImageWidth) >> 1;
            int y = (nDrawRegionHeight - nFPImageHeight) >> 1;

            int nResult = ImportDll.PPL501F_SetDisplayedFPImageAt(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, g_hMainWnd, x, y, nFPImageWidth, nFPImageHeight);
            if (nResult != 0)
            {
                string strError = "PPL501F_SetDisplayedFPImageAt(), error = " + nResult.ToString();
                System.Windows.MessageBox.Show(strError, "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }

            if (fun == null)
                fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);
            Int32 ret = ImportDll.PPL501F_SignatureStatusCallback(m_deviceID, fun);

            if (_RealDataCallback == null)
                _RealDataCallback = new ImportDll.NOTIFYREALTIMESIGNDATA(RealTimeDataCallback);

            long retlong = ImportDll.PPL501F_RealTimeSignatureDataCallback(m_deviceID, _RealDataCallback);

            EnableL501FBtn(true);
        }

        private void InitialW300Device()
        {
            bool result = ImportDll.PPW300_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, g_hMainWnd, 0, 0, (int)DrawRegion.Width, (int)DrawRegion.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            if (fun == null)
                fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);
            Int32 ret = ImportDll.PPW300_SignatureStatusCallback(m_deviceID, fun);

            if (_RealDataCallback == null)
                _RealDataCallback = new ImportDll.NOTIFYREALTIMESIGNDATA(RealTimeDataCallback);

            long retlong = ImportDll.PPW300_RealTimeSignatureDataCallback(m_deviceID, _RealDataCallback);

            EnableBtn(true);
        }

        private void InitialL1000Device()
        {
            bool result = CreateSignWndOnL1000Screen();
            System.Windows.Size DrawAreaSize = new System.Windows.Size(1180, 620);
            
            if ((result == true) && (g_L1000SignWnd != null))
                result = ImportDll.PPL1000_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, g_hL1000SignWnd, 50, 20, (int)DrawAreaSize.Width, (int)DrawAreaSize.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }

            int nFPImageWidth = 107;
            int nFPImageHeight = 150;
            int nDrawRegionWidth = (int)DrawRegion.Width;
            int nDrawRegionHeight = (int)DrawRegion.Height;
            int x = ((int)DrawAreaSize.Width - nFPImageWidth) >> 1;
            int y = ((int)DrawAreaSize.Height - nFPImageHeight) >> 1;

            int nResult = ImportDll.PPL1000_SetDisplayedFPImageAt(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, g_hL1000SignWnd, x, y, nFPImageWidth, nFPImageHeight);
            if (nResult != 0)
            {
                if (nResult != (int)ImportDll.ERROR_ID.RET_PST_DEVICENOREADY)
                {
                    string strError = "PPL1000_SetDisplayedFPImageAt(), error = " + nResult.ToString();
                    System.Windows.MessageBox.Show(strError, "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                    return;
                }
            }

            ImportDll.PPL1000_EnableMouse(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, true);
            EnableL1000Btn(true);
            DrawRegion.Background = new SolidColorBrush(Colors.White);
            
            
            if (nResult == (int)ImportDll.ERROR_ID.RET_PST_DEVICENOREADY)
                textL398Status.Text = "No Finger Print Feature !";
            else
            {
                if (fun == null)
                    fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);
                Int32 ret = ImportDll.PPL1000_SignatureStatusCallback(m_deviceID, fun);

                int nMinimumScore = 20; // score range (1 ~ 255), 1 : easiest captured; 255 : hardest captured
                ret = ImportDll.PPL1000_SetCaptureFPImageThresholdValue(m_deviceID, nMinimumScore);
            }
        }

        private void InitialLC700Device()
        {
            bool result = ImportDll.PPLC700_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, g_hMainWnd, 0, 0, (int)DrawRegion.Width, (int)DrawRegion.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            if (fun == null)
                fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);
            Int32 ret = ImportDll.PPLC700_SignatureStatusCallback(m_deviceID, fun);

            if (_RealDataCallback == null)
                _RealDataCallback = new ImportDll.NOTIFYREALTIMESIGNDATA(RealTimeDataCallback);

            long retlong = ImportDll.PPLC700_RealTimeSignatureDataCallback(m_deviceID, _RealDataCallback);

            EnableBtn(true);
        }

        private void InitialE640Device()
        {
            bool result = ImportDll.PPE640_InitialDevice(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, g_hMainWnd, 0, 0, (int)DrawRegion.Width, (int)DrawRegion.Height);
            if (!result)
            {
                System.Windows.MessageBox.Show(" No Device！", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            if (fun == null)
                fun = new ImportDll.CallBackMyFun1(PPSignStatusNotify);
            Int32 ret = ImportDll.PPE640_SignatureStatusCallback(m_deviceID, fun);

            if (_RealDataCallback == null)
                _RealDataCallback = new ImportDll.NOTIFYREALTIMESIGNDATA(RealTimeDataCallback);

            long retlong = ImportDll.PPE640_RealTimeSignatureDataCallback(m_deviceID, _RealDataCallback);

            EnableBtn(true);
        }

        private void L398InitBtn_Click(object sender, RoutedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                InitialL398Device();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                InitialNatureDevice();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                InitialL500Device();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                InitialL501FDevice();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                InitialW300Device();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                InitialL1000Device();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                InitialLC700Device();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                InitialE640Device();

            m_bEnableSaveVideo = true;
        }

        private void L398UnInitBtn_Click(object sender, RoutedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
            {
                ImportDll.PPL398_CloseLed(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE);
                ImportDll.PPL398_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE);
                EnableL398Btn(false);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
            {
                ImportDll.PPNature_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE);
                EnableBtn(false);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
            {
                ImportDll.PPL500_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE);
                EnableL398Btn(false);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
            {
                ImportDll.PPL501F_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE);
                EnableL501FBtn(false);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
            {
                ImportDll.PPW300_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE);
                EnableBtn(false);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
            {
                if (g_L1000SignWnd != null)
                {
                    g_L1000SignWnd.Close();
                    g_L1000SignWnd = null;
                    g_hL1000SignWnd = IntPtr.Zero;
                }

                ImportDll.PPL1000_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE);
                EnableL1000Btn(false);
                DrawRegion.Background = m_brushOriginalDrawRegionBackground;
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
            {
                ImportDll.PPLC700_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE);
                EnableBtn(false);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
            {
                ImportDll.PPE640_UnInitialDevice(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE);
                EnableBtn(false);
            }

            m_bEnableSaveVideo = false;
            textL398Status.Text = "";
        }

        private void GetNatureDeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPNature_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPNature_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPNature_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPNature_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPNature_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPNature_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPNature_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (byte)(uVersion & 0xffff), (byte)((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetL398DeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL398_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL398_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL398_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL398_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL398_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL398_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL398_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetL500DeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL500_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL500_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL500_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL500_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL500_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL500_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL500_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetL501FDeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL501F_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL501F_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL501F_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL501F_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL501F_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL501F_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL501F_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetW300DeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPW300_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPW300_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPW300_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPW300_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPW300_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPW300_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPW300_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetL1000DeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL1000_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL1000_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPL1000_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL1000_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL1000_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPL1000_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPL1000_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetLC700DeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPLC700_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPLC700_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPLC700_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPLC700_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPLC700_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPLC700_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPLC700_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetE640DeviceInfo()
        {
            Int32 nItem = combL398DevInfo.SelectedIndex + 1;
            switch (nItem)
            {
                case ImportDll.HW_GET_STATUS:
                    {
                        IntPtr iStatus;
                        ImportDll.PPE640_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, out iStatus);
                        if (iStatus.ToInt32() == 0)
                            textL398Status.Text = "Device Connection : Successful";
                        else
                            textL398Status.Text = "Device Connection : Failed";
                    }
                    break;
                case ImportDll.HW_GET_AXIS_X:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPE640_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device X Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_AXIS_Y:
                    {
                        ImportDll.tagPPAXIS iStatus;
                        ImportDll.PPE640_getDeviceInfoPPAXIS(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Y Range : {0} - {1}", iStatus.axMin, iStatus.axMax);
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRESSURE:
                    {
                        IntPtr iStatus;
                        ImportDll.PPE640_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("Device Pressure Range : {0} - {1}", 0, iStatus.ToInt32());
                        textL398Status.Text = sb.ToString();
                    }
                    break;
                case ImportDll.HW_GET_VENDOR:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPE640_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Vendor : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_PRODUCT:
                    {
                        StringBuilder iStatus = new StringBuilder(MAX_PATH);
                        ImportDll.PPE640_getDeviceInfoString(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, iStatus);

                        textL398Status.Text = "Device Name : " + iStatus.ToString();
                    }
                    break;
                case ImportDll.HW_GET_DRV_VER:
                    {
                        IntPtr iStatus;
                        ImportDll.PPE640_getDeviceInfo(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, out iStatus);
                        StringBuilder sb = new StringBuilder();
                        Int32 uVersion = iStatus.ToInt32();
                        sb.AppendFormat("{1}.{0}", (uVersion & 0xffff), ((uVersion >> 16) & 0xffff));
                        textL398Status.Text = sb.ToString();
                    }
                    break;
            }
        }

        private void GetDevInfL398Btn_Click(object sender, RoutedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                GetL398DeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                GetNatureDeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                GetL500DeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                GetL501FDeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                GetW300DeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                GetL1000DeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                GetLC700DeviceInfo();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                GetE640DeviceInfo();
        }

        private void PadIDL398Btn_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder strRes = new StringBuilder(ImportDll.PPL398_SIGN_API_PAD_ID_LENGTH);

            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ImportDll.PPL398_GetHWPadID(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ImportDll.PPL500_GetHWPadID(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ImportDll.PPL501F_GetHWPadID(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                ImportDll.PPL1000_GetHWPadID(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                ImportDll.PPLC700_GetHWPadID(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                ImportDll.PPE640_GetHWPadID(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, strRes);

            textL398Status.Text = strRes.ToString(0, ImportDll.PPL398_SIGN_API_PAD_ID_LENGTH);
        }
        private void PenIDL398Btn_Click(object sender, RoutedEventArgs e)
        {
            UInt32 nlen = 0;
            StringBuilder strRes = new StringBuilder(ImportDll.PPL398_SIGN_API_ID_BUFFER_LENGTH);

            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ImportDll.PPL398_GetHWPenID(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, strRes, ImportDll.PPL398_SIGN_API_ID_BUFFER_LENGTH, ref nlen);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ImportDll.PPL500_GetHWPenID(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, strRes, ImportDll.PPL398_SIGN_API_ID_BUFFER_LENGTH, ref nlen);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ImportDll.PPL501F_GetHWPenID(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, strRes, ImportDll.PPL398_SIGN_API_ID_BUFFER_LENGTH, ref nlen);

            textL398Status.Text = strRes.ToString();
        }

        private void VersionL398Btn_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder strRes = new StringBuilder();

            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ImportDll.PPL398_GetHWVersionID(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ImportDll.PPL500_GetHWVersionID(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, strRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ImportDll.PPL501F_GetHWVersionID(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, strRes);

            textL398Status.Text = strRes.ToString();
        }

        private void ShowVerL398Btn_Click(object sender, RoutedEventArgs e)
        {
            m_bShow = !m_bShow;
            Int32 nRes = Convert.ToInt32(m_bShow);

            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ImportDll.PPL398_DisplayHWVersion(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nRes);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ImportDll.PPL500_DisplayHWVersion(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nRes);

            textL398Status.Text = "Show Version " + m_bShow.ToString();
        }

        private void OpenLedL398Btn_Click(object sender, RoutedEventArgs e)
        {
            Int32 nRes = 0;

            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nRes = ImportDll.PPL398_OpenLed(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nRes = ImportDll.PPL500_OpenLed(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE);

            textL398Status.Text = nRes.ToString();
        }

        private void CloseLEDL398Btn_Click(object sender, RoutedEventArgs e)
        {
            Int32 nRes = 0;

            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nRes = ImportDll.PPL398_CloseLed(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nRes = ImportDll.PPL500_CloseLed(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE);

            textL398Status.Text = nRes.ToString();
        }

        private void GetSizeL398Btn_Click(object sender, RoutedEventArgs e)
        {
            Int32 nRes = 0;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nRes = ImportDll.PPL398_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                nRes = ImportDll.PPNature_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nRes = ImportDll.PPL500_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nRes = ImportDll.PPL501F_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                nRes = ImportDll.PPW300_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                nRes = ImportDll.PPL1000_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                nRes = ImportDll.PPLC700_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                nRes = ImportDll.PPE640_GetTotalPacketsNumber(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE);

            textL398Status.Text = nRes.ToString();
            combL398GetPoint.Items.Clear();
            for (int i = 0; i < nRes; i++)
            {
                combL398GetPoint.Items.Add(Convert.ToSingle(i));
            }
            combL398GetPoint.SelectedIndex = 0;
        }

        private void GetPointL398Btn_Click(object sender, RoutedEventArgs e)
        {
            if (combL398GetPoint.Items.Count <= 0)
                return;

            Int32 nItem = combL398GetPoint.SelectedIndex;

            if (nItem < 0)
                nItem = 0;

            ImportDll.tagPACKETS pst = new ImportDll.tagPACKETS();

            pst.btn = nItem;
            Int32 ret = 0;
            IntPtr tmpBuf = IntPtr.Zero;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
            {
                ret = ImportDll.PPL398_getPackets(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, ref pst);
                tmpBuf = ImportDll.PPL398_GetInkPointTime(m_deviceID,combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
            {
                ret = ImportDll.PPNature_getPackets(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, ref pst);
                tmpBuf = ImportDll.PPNature_GetInkPointTime(m_deviceID,combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
            {
                ret = ImportDll.PPL500_getPackets(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, ref pst);
                tmpBuf = ImportDll.PPL500_GetInkPointTime(m_deviceID, combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
            {
                ret = ImportDll.PPL501F_getPackets(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, ref pst);
                tmpBuf = ImportDll.PPL501F_GetInkPointTime(m_deviceID, combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
            {
                ret = ImportDll.PPW300_getPackets(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, ref pst);
                tmpBuf = ImportDll.PPW300_GetInkPointTime(m_deviceID, combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
            {
                ret = ImportDll.PPL1000_getPackets(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, ref pst);
                tmpBuf = ImportDll.PPL1000_GetInkPointTime(m_deviceID, combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
            {
                ret = ImportDll.PPLC700_getPackets(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, ref pst);
                tmpBuf = ImportDll.PPLC700_GetInkPointTime(m_deviceID, combL398GetPoint.SelectedIndex);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
            {
                ret = ImportDll.PPE640_getPackets(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, ref pst);
                tmpBuf = ImportDll.PPE640_GetInkPointTime(m_deviceID, combL398GetPoint.SelectedIndex);
            }

            StringBuilder sb = new StringBuilder();
            string timeString = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(tmpBuf);
            if (ret == 0)
            {
                sb.AppendFormat("index={0},X={1},Y={2},pressure={3}, time = {4},End={5}", 
                    pst.btn, pst.X, pst.Y, pst.Press,timeString,pst.bStrokeEnd?1:0);
            }
            else
            {
                sb.AppendFormat("code: {0} ", ret);
            }
            textL398Status.Text = sb.ToString();
            if (tmpBuf != IntPtr.Zero)
            {
                if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                {
                    ImportDll.PPNature_FreeInkPointTime(m_deviceID,tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                {
                    ImportDll.PPL398_FreeInkPointTime(m_deviceID, tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                {
                    ImportDll.PPL500_FreeInkPointTime(m_deviceID, tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                {
                    ImportDll.PPL501F_FreeInkPointTime(m_deviceID, tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                {
                    ImportDll.PPW300_FreeInkPointTime(m_deviceID, tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                {
                    ImportDll.PPL1000_FreeInkPointTime(m_deviceID, tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                {
                    ImportDll.PPLC700_FreeInkPointTime(m_deviceID, tmpBuf);
                }
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                {
                    ImportDll.PPE640_FreeInkPointTime(m_deviceID, tmpBuf);
                }
            }
        }

        private void SaveDrawingImage()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Image.SelectedIndex);

            string strExt = ".bmp";
            if (nItem == 0)
                strExt = ".bmp";
            else if (nItem == 1)
                strExt = ".jpg";
            else if (nItem == 2)
                strExt = ".png";
            else if (nItem == 3)
                strExt = ".gif";
            else if (nItem == 4)
                strExt = ".tiff";
            else if (nItem == 5)
                strExt = ".pdf";
            else if (nItem == 6)
                strExt = ".svg";

            if (nItem >= 5)
                nItem++;

            string strName = DateTime.Now.ToString("yyyyMMddHHmmss") + strExt;

            string strFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + strName;
            StringBuilder sb = new StringBuilder(strFileName);

            int index = comboBox_dpi.SelectedIndex;
            ComboBoxItem item = (ComboBoxItem)comboBox_dpi.SelectedItem;
            string strDpi = item.Content.ToString ();
            int dpi = index;// int.Parse(strDpi);


            Int32 ret = 0;
            nItem = nItem + 1;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ret = ImportDll.PPL398_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, sb, dpi);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                ret = ImportDll.PPNature_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, sb, dpi);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ret = ImportDll.PPL500_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, sb, dpi);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ret = ImportDll.PPL501F_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, sb, dpi);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                ret = ImportDll.PPW300_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, sb, dpi);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
            {
                string strDrawImagePath = strFileName;
                if (nItem == 7)
                {
                    strDrawImagePath = strDrawImagePath.Replace(".pdf", ".jpg");
                    StringBuilder sbDrawImagePath = new StringBuilder(strDrawImagePath);
                    ret = ImportDll.PPL1000_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, 2, sbDrawImagePath, dpi);
                }
                else if (nItem == 8)
                {
                    strDrawImagePath = strDrawImagePath.Replace(".svg", ".jpg");
                    StringBuilder sbDrawImagePath = new StringBuilder(strDrawImagePath);
                    ret = ImportDll.PPL1000_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, 2, sbDrawImagePath, dpi);
                }

                ret = ImportDll.PPL1000_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, sb, dpi);

                ImageBrush imgBrush = new ImageBrush();
                imgBrush.ImageSource = new BitmapImage(new Uri(strDrawImagePath, UriKind.Absolute));
                imgBrush.Stretch = Stretch.Uniform;
                DrawRegion.Background = imgBrush;
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                ret = ImportDll.PPLC700_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, sb, dpi);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                ret = ImportDll.PPE640_SaveDrawingImage(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, sb, dpi);

            System.Threading.Thread.Sleep(100);
            textL398Status.Text = strFileName + ", result : " + ret;
        }

        private void SaveImageL398Btn_Click(object sender, RoutedEventArgs e)
        {
            SaveDrawingImage();
        }

        public void PPSignStatusNotify(Int32 nVal)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
            {
                switch(nVal)
                {
                    case (int)ImportDll.W300_HOTKEY.W300_CLEAN_KEY_CLICK:
                        textL398Status.Text = "Sign Canceled ! Clearing data, please wait...";
                        System.Windows.Forms.Application.DoEvents();
                        ImportDll.PPW300_Clear(m_deviceID);
                        textL398Status.Text = "You may start signing again !";
                        break;
                    case (int)ImportDll.W300_HOTKEY.W300_EXTRA_KEY_CLICK:
                        textL398Status.Text = "Extra Key Clicked !";
                        break;
                    case (int)ImportDll.W300_HOTKEY.W300_LEFT_KEY_CLICK:
                        textL398Status.Text = "Left Key Clicked !";
                        break;
                    case (int)ImportDll.W300_HOTKEY.W300_MIDDLE_KEY_CLICK:
                        textL398Status.Text = "Middle Key Clicked !";
                        break;
                    case (int)ImportDll.W300_HOTKEY.W300_RIGHT_KEY_CLICK:
                        textL398Status.Text = "Right Key Clicked !";
                        break;
                }
            }
            else
            {
                if (nVal == 2)
                {
                    textL398Status.Text = "FingerPrint Image captured completed.";

                    if (g_L1000SignWnd != null)
                    {
                        g_L1000SignWnd.g_tbStatus.Text = textL398Status.Text;
                    }
                    return;
                }
                else if (nVal == 1)
                {
                    textL398Status.Text = "Sign OK .";
                    SaveDrawingImage();
                }
                else
                {
                    textL398Status.Text = "Sign Canceled ! Clearing data, please wait...";
                }

                System.Windows.Forms.Application.DoEvents();

                if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                    ImportDll.PPL398_Clear(m_deviceID);
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                    ImportDll.PPL500_Clear(m_deviceID);
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                    ImportDll.PPL501F_Clear(m_deviceID);
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                    ImportDll.PPLC700_Clear(m_deviceID);
                else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                    ImportDll.PPE640_Clear(m_deviceID);

                textL398Status.Text = "You may start signing again !";
            }
        }

        public static ushort LOWORD(uint value)
        {
            return (ushort)(value & 0xFFFF);
        }
        public static ushort HIWORD(uint value)
        {
            return (ushort)(value >> 16);
        }

        private void RealTimeDataCallback(IntPtr wParam, IntPtr lParam)
        {
            int wParamInt = wParam.ToInt32();
            int lParamInt = lParam.ToInt32();
            //decode real-time data...
            int nRealTimeX = (int)((LOWORD((uint)wParamInt)) / 65535.0 * (int)DrawRegion.Width);
            int nRealTimeY = (int)((HIWORD((uint)wParamInt)) / 65535.0 * (int)DrawRegion.Height);
            int nPressure = (int)LOWORD((uint)lParamInt);
            bool bPenDown = HIWORD((uint)lParamInt) == 0 ? false : true;

            if (bPenDown)
            {
                RealTimeDataBlock.Text = "(" + nRealTimeX + "," + nRealTimeY + "," + nPressure + "," + "pen-down)";
            }
            else
            {
                RealTimeDataBlock.Text = "(" + nRealTimeX + "," + nRealTimeY + "," + nPressure + "," + "pen-up)";
            }
        }

        private IntPtr strBuf = IntPtr.Zero;
        private void EncodeNatureData()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPNature_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPNature_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeL398Data()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPL398_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPL398_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeL500Data()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPL500_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPL500_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeL501FData()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPL501F_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPL501F_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeW300Data()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPW300_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPW300_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeL1000Data()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPL1000_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPL1000_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeLC700Data()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPLC700_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPLC700_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeE640Data()
        {
            Int32 nItem = combL398Encode.SelectedIndex;
            nItem += 1;
            if (!strBuf.Equals(IntPtr.Zero))
            {
                ImportDll.PPE640_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
            }
            strBuf = ImportDll.PPE640_PacketsBase64Encode(m_deviceID, nItem);
            string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strBuf);

            textBoxfile.Text = str;
        }

        private void EncodeL398Btn_Click(object sender, RoutedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                EncodeL398Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                EncodeNatureData();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                EncodeL500Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                EncodeL501FData();
            else if(m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                EncodeW300Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                EncodeL1000Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                EncodeLC700Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                EncodeE640Data();
        }

        private void DecodeL398Data()
        {
            if (strBuf == IntPtr.Zero)
                return;

            if (textBoxfile.Text.ToString() == "")
                return;
            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);
            ImportDll.PPL398_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPL398_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }

            Int32 number = ImportDll.PPL398_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPL398_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPL398_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPL398_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPL398_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeNatureData()
        {
            if (strBuf == IntPtr.Zero)
                return;
            if (textBoxfile.Text.ToString() == "")
                return;
            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;


            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);

            ImportDll.PPNature_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);


            if (nItem != 6)
            {
                ImportDll.PPNature_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }
            Int32 number = ImportDll.PPNature_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();


            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPNature_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPNature_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPNature_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPNature_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeL500Data()
        {
            if (strBuf == IntPtr.Zero)
                return;

            if (textBoxfile.Text.ToString() == "")
                return;
            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);

            ImportDll.PPL500_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPL500_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }

            Int32 number = ImportDll.PPL500_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPL500_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPL500_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPL500_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPL500_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeL501FData()
        {
            if (strBuf == IntPtr.Zero)
                return;

            if (textBoxfile.Text.ToString() == "")
                return;
            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);

            ImportDll.PPL501F_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPL501F_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }

            Int32 number = ImportDll.PPL501F_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPL501F_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPL501F_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPL501F_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPL501F_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeW300Data()
        {
            if (strBuf == IntPtr.Zero)
                return;

            if (textBoxfile.Text.ToString() == "")
                return;
            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);
            ImportDll.PPW300_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPW300_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }

            Int32 number = ImportDll.PPW300_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPW300_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPW300_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPW300_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPW300_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeL1000Data()
        {
            if (strBuf == IntPtr.Zero)
                return;
            if (textBoxfile.Text.ToString() == "")
                return;
            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;


            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);
            ImportDll.PPL1000_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPL1000_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }
            Int32 number = ImportDll.PPL1000_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPL1000_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPL1000_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPL1000_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPL1000_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeLC700Data()
        {
            if (strBuf == IntPtr.Zero)
                return;

            if (textBoxfile.Text.ToString() == "")
                return;

            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);

            ImportDll.PPLC700_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPLC700_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }

            Int32 number = ImportDll.PPLC700_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPLC700_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPLC700_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPLC700_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPLC700_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeE640Data()
        {
            if (strBuf == IntPtr.Zero)
                return;

            if (textBoxfile.Text.ToString() == "")
                return;

            SaveFileDialog dlg = new SaveFileDialog();
            UInt32 nItem = Convert.ToUInt32(combL398Encode.SelectedIndex);

            if (nItem == 0)
                dlg.Filter = "BMP文件|*.bmp";
            else if (nItem == 1)
                dlg.Filter = "JPG文件|*.jpg";
            else if (nItem == 2)
                dlg.Filter = "PNG文件|*.png";
            else if (nItem == 3)
                dlg.Filter = "GIF文件|*.gif";
            else if (nItem == 4)
                dlg.Filter = "TIFF文件|*.tiff";

            nItem = nItem + 1;
            if (nItem != 6)
            {
                dlg.AddExtension = true;
                dlg.FileName = "PPSignDecodeImage";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
            }
            StringBuilder sbfile = new StringBuilder(dlg.FileName);
            StringBuilder sbcontent = new StringBuilder(textBoxfile.Text);

            ImportDll.PPE640_Base64Decode(m_deviceID, nItem, sbcontent, sbfile);

            if (nItem != 6)
            {
                ImportDll.PPE640_PacketsBase64EncodeFree(m_deviceID, strBuf);
                strBuf = IntPtr.Zero;
                return;
            }

            Int32 number = ImportDll.PPE640_GetTotalDecodePacketsNumber(m_deviceID);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < number; i++)
            {
                Int32 X, Y, E;
                X = ImportDll.PPE640_GetDecodePacketsData(m_deviceID, i, 1);
                Y = ImportDll.PPE640_GetDecodePacketsData(m_deviceID, i, 2);
                E = ImportDll.PPE640_GetDecodePacketsData(m_deviceID, i, 3);

                sb.AppendFormat("index = {0}, X = {1}, Y = {2}, End = {3}\r\n", i, X, Y, E);

            }
            textBoxfile.Text = sb.ToString();

            ImportDll.PPE640_PacketsBase64EncodeFree(m_deviceID, strBuf);
            strBuf = IntPtr.Zero;
        }

        private void DecodeL398Btn_Click(object sender, RoutedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                DecodeL398Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                DecodeNatureData();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                DecodeL500Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                DecodeL501FData();
            else if(m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                DecodeW300Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                DecodeL1000Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                DecodeLC700Data();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                DecodeE640Data();
        }

        private void combL398Encode_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            textBoxfile.Text = "";
        }

        private void combL398Color_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            UInt32 ulR = 0, ulG = 0, ulB = 0;

            if (combL398Color.SelectedItem == null)
                return;

            string color = combL398Color.SelectedItem.ToString();
            if (color.CompareTo("Red") == 0)
            {
                ulR = 255;
            }
            else if (color.CompareTo("Green") == 0)
            {
                ulG = 255;
            }
            else if (color.CompareTo("Blue") == 0)
            {
                ulB = 255;
            }
            else if (color.CompareTo("Yellow") == 0)
            {
                ulR = 255;
                ulG = 255;
            }
            else if (color.CompareTo("White") == 0)
            {
                ulR = 255;
                ulG = 255;
                ulB = 255;
            }
            else
            {
                ulR = 0;
                ulG = 0;
                ulB = 0;
            }
            Int32 nVal = 0;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                nVal = ImportDll.PPNature_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                nVal = ImportDll.PPW300_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                nVal = ImportDll.PPL1000_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                nVal = ImportDll.PPLC700_SetPenColor(m_deviceID, ulR, ulG, ulB);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                nVal = ImportDll.PPE640_SetPenColor(m_deviceID, ulR, ulG, ulB);

            textL398Status.Text = nVal.ToString();
        }

        private void SetNaturePenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPNature_SetPenStyle(m_deviceID, nItem);

//            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetL398PenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPL398_SetPenStyle(m_deviceID, nItem);

//            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetL500PenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPL500_SetPenStyle(m_deviceID, nItem);

//            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetL501FPenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPL501F_SetPenStyle(m_deviceID, nItem);

//            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetW300PenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPW300_SetPenStyle(m_deviceID, nItem);

//            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetL1000PenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPL1000_SetPenStyle(m_deviceID, nItem);

//            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetLC700PenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPLC700_SetPenStyle(m_deviceID, nItem);

            //            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void SetE640PenStyle()
        {
            UInt32 nItem = Convert.ToUInt32(combL398Style.SelectedIndex);
            Int32 nVal = ImportDll.PPE640_SetPenStyle(m_deviceID, nItem);

            //            combWidth.IsEnabled = false;
            textL398Status.Text = nVal.ToString();
        }

        private void combL398Style_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                SetL398PenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                SetNaturePenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                SetL500PenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                SetL501FPenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                SetW300PenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                SetL1000PenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                SetLC700PenStyle();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                SetE640PenStyle();
        }

        private void ReadCertL398Btn_Click(object sender, RoutedEventArgs e)
        {
            textL398Status.Text = "";
            Int32 nItem = combL398ReadCert.SelectedIndex + 1;

            string strFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\"+ DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            StringBuilder filename = new StringBuilder(strFileName);

            Int32 nVal = 0;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_ReadDeviceData(m_deviceID, filename, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_ReadDeviceData(m_deviceID, filename, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_ReadDeviceData(m_deviceID, filename, nItem);

            textL398Status.Text = "download device data to " + strFileName + ", return=" + nVal.ToString();
        }

        private void GetCertL398Btn_Click(object sender, RoutedEventArgs e)
        {
            textL398Status.Text = "";
            Int32 nItem = combL398GetCert.SelectedIndex + 1;
            
            StringBuilder filename = new StringBuilder("sample.txt");
            Int32 nClear = Convert.ToInt32(false);

            Int32 nVal = 0;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_SaveDeviceData(m_deviceID, filename, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_SaveDeviceData(m_deviceID, filename, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_SaveDeviceData(m_deviceID, filename, nItem);

            textL398Status.Text = "upload sample.txt into device, return=" + nVal.ToString();
        }
        private void DelFileL398Btn_Click(object sender, RoutedEventArgs e)
        {
            Int32 nItem = combL398DelFile.SelectedIndex;

            Int32 nVal = 0;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_ClearDeviceData(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_ClearDeviceData(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_ClearDeviceData(m_deviceID, nItem);

            textL398Status.Text = "return=" + nVal.ToString();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowInteropHelper helper = new WindowInteropHelper(this);
            g_hMainWnd = helper.Handle;
            m_brushOriginalDrawRegionBackground = DrawRegion.Background;
        }

        private void textClipX_TextChanged(object sender, TextChangedEventArgs e)
        {
        }
        private void textClipY_TextChanged(object sender, TextChangedEventArgs e)
        {
        }
        private void SetClipL398Btn_Click(object sender, RoutedEventArgs e)
        {
            string strX = textClipX.Text;
            string strY = textClipY.Text;
            UInt32 nClipX = 0;
            UInt32 nClipY = 0;

            try
            {
                if (strX != "")
                    nClipX = Convert.ToUInt32(strX);
                if (strY != "")
                    nClipY = Convert.ToUInt32(strY);
            }
            catch (System.FormatException except)
            {
                string strMsg = except.Message;
                System.Windows.MessageBox.Show("Input Clip X, Y should be positive value !", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }
            catch (System.OverflowException ovexcept)
            {
                string strMsg = ovexcept.Message;
                System.Windows.MessageBox.Show("Input Clip X, Y should be positive value !", "PPSignSDKDemo", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                return;
            }

            Int32 nTure = Convert.ToInt32(true);
            Int32 nVal = 0; 
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                nVal = ImportDll.PPNature_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                nVal = ImportDll.PPW300_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                nVal = ImportDll.PPL1000_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                nVal = ImportDll.PPLC700_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                nVal = ImportDll.PPE640_SetSaveCenterImageClip(m_deviceID, nTure, nClipX, nClipY);

            textL398Status.Text = nVal.ToString();
            System.Threading.Thread.Sleep(50);

            string strSrc = strfile + strfilename;
            if (File.Exists(strSrc))
                File.Delete(strSrc);
        }
        private static string strfile = System.Environment.GetEnvironmentVariable("TEMP");
        private static string strfilename = "\\PPSignTempImage.bmp";

        private void ClearL398Btn_Click(object sender, RoutedEventArgs e)
        {
            textL398Status.Text = "Clearing data, please wait...";
            System.Windows.Forms.Application.DoEvents();

            Int32 nVal = 0;  
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_Clear(m_deviceID);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                nVal = ImportDll.PPNature_Clear(m_deviceID);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_Clear(m_deviceID);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_Clear(m_deviceID);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                nVal = ImportDll.PPW300_Clear(m_deviceID);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
            {
                DrawRegion.Background = new SolidColorBrush(Colors.White);
                nVal = ImportDll.PPL1000_Clear(m_deviceID);
            }
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                nVal = ImportDll.PPLC700_Clear(m_deviceID);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                nVal = ImportDll.PPE640_Clear(m_deviceID);

            textL398Status.Text = "Clear finished, result = " + nVal.ToString();
        }

        private void CalL398Btn_Click(object sender, RoutedEventArgs e)
        {
            CalDlg dlg = new CalDlg();
            dlg.Owner = this;
            dlg.ShowDialog();
        }

        private void AboutL398Btn_Click(object sender, RoutedEventArgs e)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ImportDll.PPL398_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                ImportDll.PPNature_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ImportDll.PPL500_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ImportDll.PPL501F_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                ImportDll.PPW300_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                ImportDll.PPL1000_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                ImportDll.PPLC700_AboutBox();
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                ImportDll.PPE640_AboutBox();
        }
 
        private void combWidth_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            UInt32 nItem = Convert.ToUInt32(combWidth.SelectedIndex) + 1;
            Int32 nVal = 0; 
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                nVal = ImportDll.PPL398_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                nVal = ImportDll.PPNature_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                nVal = ImportDll.PPL500_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                nVal = ImportDll.PPL501F_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                nVal = ImportDll.PPW300_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                nVal = ImportDll.PPL1000_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                nVal = ImportDll.PPLC700_SetPenWidth(m_deviceID, nItem);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                nVal = ImportDll.PPE640_SetPenWidth(m_deviceID, nItem);

            textL398Status.Text = nVal.ToString();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            L398UnInitBtn_Click(this, e);
            Close();
        }

        private void comboBox_device_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = this.comboBox_device.SelectedIndex;
            if (index == 0 || index == 2)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE;
            else if (index == 1)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE;
            else if (index == 3)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE;
            else if (index == 4)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE;
            else if (index == 5)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE;
            else if (index == 6)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE;
            else if (index == 7)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE;
            else if (index == 8)
                m_deviceID = ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE;
        }

        private void SaveVideoBtn_Click(object sender, RoutedEventArgs e)
        {
            UInt32 nItem = Convert.ToUInt32(ComboVideo.SelectedIndex);

            string strExt = ".mp4";
            if (nItem == 0)
                strExt = ".mp4";
            else if (nItem == 1)
                strExt = ".wmv";

            string strName = DateTime.Now.ToString("yyyyMMddHHmmss") + strExt;
            string strFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + strName;
            StringBuilder sb = new StringBuilder(strFileName);

            int index = comboBox_FPS.SelectedIndex;
            ComboBoxItem item = (ComboBoxItem)comboBox_FPS.SelectedItem;
            string strDpi = item.Content.ToString();
            int FPS = index+1;// int.Parse(strDpi);

            Int32 ret = 0;
            nItem = nItem + 1;
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ret = ImportDll.PPL398_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                ret = ImportDll.PPNature_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ret = ImportDll.PPL500_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ret = ImportDll.PPL501F_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                ret = ImportDll.PPW300_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                ret = ImportDll.PPL1000_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                ret = ImportDll.PPLC700_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, nItem, FPS, sb);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                ret = ImportDll.PPE640_SaveDrawingVideo(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, nItem, FPS, sb);

            System.Threading.Thread.Sleep(100);
            textL398Status.Text = strFileName + ", result : " + ret;
        }

        private void EnableVideoBtn_Click(object sender, RoutedEventArgs e)
        {
            ClearL398Btn.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent));

            if (m_bEnableSaveVideo)
            {
                EnableVideoBtn.Content = "Disable";

                SaveVideoBtn.IsEnabled = true;
                ComboVideo.IsEnabled = true;
                comboBox_FPS.IsEnabled = true;

                SaveDrawingVideoAction(true);
            }
            else
            {
                EnableVideoBtn.Content = "Enable";

                SaveVideoBtn.IsEnabled = false;
                ComboVideo.IsEnabled = false;
                comboBox_FPS.IsEnabled = false;

                SaveDrawingVideoAction(false);
            }

            m_bEnableSaveVideo = !m_bEnableSaveVideo;
        }

        private void SaveDrawingVideoAction(bool bEnable)
        {
            if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE)
                ImportDll.PPL398_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPL398_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE)
                ImportDll.PPNature_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPNature_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE)
                ImportDll.PPL500_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPL500_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE)
                ImportDll.PPL501F_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPL501F_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE)
                ImportDll.PPW300_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPW300_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE)
                ImportDll.PPL1000_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPL1000_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE)
                ImportDll.PPLC700_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPLC700_DEVICE, bEnable);
            else if (m_deviceID == ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE)
                ImportDll.PPE640_EnableSaveVideoData(ImportDll.DEVICE_TYPE_ID.PPE640_DEVICE, bEnable);
        }

        private bool CreateSignWndOnL1000Screen()
        {
            bool result = false;

            foreach (Screen currentScr in Screen.AllScreens)
            {
                if ((currentScr.Bounds.Width == L1000_SCREEN_WIDTH) &&
                    (currentScr.Bounds.Height == L1000_SCREEN_HEIGHT))
                {
                    // create L1000 SignWnd Form...
                    g_L1000SignWnd = new L1000SignWnd(this);
                    if (g_L1000SignWnd != null)
                    {
                        g_L1000SignWnd.Left = currentScr.Bounds.Left;
                        g_L1000SignWnd.Top = currentScr.Bounds.Top;
                        g_L1000SignWnd.Width = L1000_SCREEN_WIDTH;
                        g_L1000SignWnd.Height = L1000_SCREEN_HEIGHT;
                        g_L1000SignWnd.Show();

                        WindowInteropHelper helper = new WindowInteropHelper(g_L1000SignWnd);
                        g_hL1000SignWnd = helper.Handle;
                        result = true;
                    }
                    break;
                }
            }

            return result;
        }
    }
}
